package com.project.controller;

import com.project.bean.SaleCarBean;
import com.project.bean.UserBean;
import com.project.service.ISaleCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 销售车controller
 */
@RequestMapping("saleCar")
@RestController
public class SaleCarController {

    @Autowired
    private ISaleCarService saleCarService;

    //通过销售员id查询销售车商品集合，同时查询商品名称、品牌、建议销售价、库存数量
    @RequestMapping("findById")
    List<SaleCarBean> findById(HttpServletRequest request){
        UserBean loginUser = (UserBean) request.getSession().getAttribute("loginUser");
        return saleCarService.findById(loginUser.getId());
    }

    //添加销售商品
    @RequestMapping("add")
    public String add(Integer productId,HttpServletRequest request){
        UserBean loginUser = (UserBean) request.getSession().getAttribute("loginUser");
        saleCarService.add(productId, loginUser.getId());
        return "ok";
    }

    //修改销售商品数量
    @RequestMapping("updatePriceAndNumById")
    public String updatePriceAndNumById(Integer saleCarId,Integer newNum){
        saleCarService.updatePriceAndNumById(saleCarId, newNum);
        return "ok";
    }

    //通过销售车id移除销售车商品
    @RequestMapping("delById")
    public String delById(Integer saleCarId){
        saleCarService.delById(saleCarId);
        return "ok";
    }
}
